package com.jjb.www.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.layout.ShapeRecyclerView;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AnsweringDetailsApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.ui.activity.AnsweringDetailsActivity;
import com.jjb.www.ui.activity.ErrorPostActivity;

/**
 * author : Android CRG
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/11/05
 * desc   : 可进行拷贝的副本
 */
public final class AansweringDetails3Adapter extends AppAdapter<AnsweringDetailsApi.Bean.QuestionSonListDTO> {
    private String mQuestionType;
    private String mOrderNumber;
    public AansweringDetails3Adapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvTitle;
        private ShapeRecyclerView mRvQuestion;
        private ShapeTextView mTvIsTrue;
        private ShapeTextView mTvTrueAnswer;
        private ShapeTextView mTvAnswer;
        private AansweringDetails4Adapter adapter;
        private ShapeLinearLayout mLlError;



        private ViewHolder() {
            super(R.layout.item_answering_details3);
            mLlError = findViewById(R.id.ll_error);
            mTvTitle = findViewById(R.id.tv_title);
            mRvQuestion = findViewById(R.id.rv_question);
            mTvIsTrue = findViewById(R.id.tv_is_true);
            mTvTrueAnswer = findViewById(R.id.tv_true_answer);
            mTvAnswer = findViewById(R.id.tv_answer);
            adapter = new AansweringDetails4Adapter(getContext());
            mRvQuestion.setLayoutManager(new LinearLayoutManager(getContext()));
            mRvQuestion.setAdapter(adapter);
            setIsRecyclable(false);
        }

        @Override
        public void onBindView(int position) {
            AnsweringDetailsApi.Bean.QuestionSonListDTO bean = getItem(position);
            mLlError.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.putExtra("paperId", AnsweringDetailsActivity.PaperId);
                    intent.putExtra("type",bean.getType()+"");
                    intent.putExtra("question_id",bean.getQuestion_id()+"");
                    intent.putExtra("order_number",mOrderNumber);
                    intent.putExtra("question_type",mQuestionType);
                    intent.setClass(getContext(), ErrorPostActivity.class);
                    getContext().startActivity(intent);
                }
            });

            adapter.setTag(bean.getAnswer_sort());
            adapter.setData(bean.getQuestion_answer());
            mTvTitle.setText("["+bean.getType_test()+"]"+bean.getTitle());
            if (( bean.getIs_true()==1)){
                //答题正确
                mTvIsTrue.setText("作答正确");
                mTvIsTrue.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_09BB07))
                        .intoTextColor();
            }else {
                //作答错误
                mTvIsTrue.setText("作答错误");
                mTvIsTrue.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_E34D59))
                        .intoTextColor();
            }
            mTvTrueAnswer.setText("正确答案："+bean.getTrue_answer());
            if ("".equals(bean.getAnswer())){
                mTvAnswer.setVisibility(View.GONE);
            }else {
                mTvAnswer.setVisibility(View.VISIBLE);
                mTvAnswer.setText("答题解析:"+bean.getAnswer());
            }

        }
    }
    public void setItemSel(String  order_number,String question_type) {
        this.mQuestionType = question_type;
        this.mOrderNumber = order_number;
    }
}